package com.nasarius.bank.scorecard.dao.impl;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;
import org.springframework.stereotype.Repository;

import com.ibatis.sqlmap.client.SqlMapClient;
import com.nasarius.bank.scorecard.dao.SurveyDetailsDAO;
import com.nasarius.bank.scorecard.domain.SurveyDetails;
import com.nasarius.bank.scorecard.domain.SurveyDetailsExample;
@Repository
public class SurveyDetailsDAOImpl extends SqlMapClientDaoSupport implements SurveyDetailsDAO {

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
	@Autowired
    public SurveyDetailsDAOImpl(/*@Qualifier("sqlMapClient")*/SqlMapClient sqlMapClient) {
        super();
        setSqlMapClient(sqlMapClient);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public int countSurveyDetailsByExample(SurveyDetailsExample example) {
        Integer count = (Integer)  getSqlMapClientTemplate().queryForObject("survey_details.ibatorgenerated_countByExample", example);
        return count;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public int deleteSurveyDetailsByExample(SurveyDetailsExample example) {
        int rows = getSqlMapClientTemplate().delete("survey_details.ibatorgenerated_deleteByExample", example);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public int deleteSurveyDetailsByPrimaryKey(Integer surveyid) {
        SurveyDetails key = new SurveyDetails();
        key.setSurveyid(surveyid);
        int rows = getSqlMapClientTemplate().delete("survey_details.ibatorgenerated_deleteByPrimaryKey", key);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public Integer insertSurveyDetails(SurveyDetails record) {
        return (Integer)getSqlMapClientTemplate().insert("survey_details.ibatorgenerated_insert", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public void insertSurveyDetailsSelective(SurveyDetails record) {
        getSqlMapClientTemplate().insert("survey_details.ibatorgenerated_insertSelective", record);
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    @SuppressWarnings("unchecked")
    public List<SurveyDetails> selectSurveyDetailsByExample(SurveyDetailsExample example) {
        List<SurveyDetails> list = getSqlMapClientTemplate().queryForList("survey_details.ibatorgenerated_selectByExample", example);
        return list;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public SurveyDetails selectSurveyDetailsByPrimaryKey(Integer surveyid) {
        SurveyDetails key = new SurveyDetails();
        key.setSurveyid(surveyid);
        SurveyDetails record = (SurveyDetails) getSqlMapClientTemplate().queryForObject("survey_details.ibatorgenerated_selectByPrimaryKey", key);
        return record;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public int updateSurveyDetailsByExampleSelective(SurveyDetails record, SurveyDetailsExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("survey_details.ibatorgenerated_updateByExampleSelective", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public int updateSurveyDetailsByExample(SurveyDetails record, SurveyDetailsExample example) {
        UpdateByExampleParms parms = new UpdateByExampleParms(record, example);
        int rows = getSqlMapClientTemplate().update("survey_details.ibatorgenerated_updateByExample", parms);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public int updateSurveyDetailsByPrimaryKeySelective(SurveyDetails record) {
        int rows = getSqlMapClientTemplate().update("survey_details.ibatorgenerated_updateByPrimaryKeySelective", record);
        return rows;
    }

    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public int updateSurveyDetailsByPrimaryKey(SurveyDetails record) {
        int rows = getSqlMapClientTemplate().update("survey_details.ibatorgenerated_updateByPrimaryKey", record);
        return rows;
    }
    
    /**
     * This method was generated by Apache iBATIS ibator.
     * This method corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    public int updateSurveyDetailsCompleteIndicator(Integer surveyId) {
        SurveyDetails key = new SurveyDetails();
        key.setSurveyid(surveyId);
        key.setCompleteindicator("Y");
        int rows = getSqlMapClientTemplate().update("survey_details.ibatorgenerated_updateCompleteIndicator", key);
        return rows;
    }

    /**
     * This class was generated by Apache iBATIS ibator.
     * This class corresponds to the database table survey_details
     *
     * @ibatorgenerated Sun Mar 13 00:13:58 IST 2011
     */
    private static class UpdateByExampleParms extends SurveyDetailsExample {
        private Object record;

        public UpdateByExampleParms(Object record, SurveyDetailsExample example) {
            super(example);
            this.record = record;
        }

        @SuppressWarnings("unused")
		public Object getRecord() {
            return record;
        }
    }
    @SuppressWarnings("unchecked")
	public List<SurveyDetails> selectAllSurveyDetails() {
		 List<SurveyDetails> list = getSqlMapClientTemplate().queryForList("survey_details.ibatorgenerated_selectAll");
	        return list;
	}
    @SuppressWarnings("unchecked")
	public List<SurveyDetails> selectAllCompletedSurveyDetails(String userName) {
		 List<SurveyDetails> list = getSqlMapClientTemplate().queryForList("survey_details.ibatorgenerated_selectAllCompleted", userName);
	        return list;
	}
    @SuppressWarnings("unchecked")
	public List<SurveyDetails> selectSurveyByName(String surveyName) {
        SurveyDetails key = new SurveyDetails();
        key.setSurveyname(surveyName.trim());
		List<SurveyDetails> list = getSqlMapClientTemplate().queryForList("survey_details.ibatorgenerated_selectBySurveyName", key);
	        return list;
	}
    
	@SuppressWarnings("unchecked")
	@Override
	public List<SurveyDetails> surveyDetailsByBankCode(List<String> bankCodes,
			Date startdate, Date enddate) {
		Map<String,Object> criteria= new HashMap<String,Object>();   
		criteria.put("bankCodeList",bankCodes);
		criteria.put("startdate",startdate);
		criteria.put("enddate",enddate);
		List<SurveyDetails> list =(List<SurveyDetails>) getSqlMapClientTemplate().queryForList("survey_details.ibatorgenerated_surveyDetailsByBankCode", criteria);
	    return list;
	}
}